﻿#include "StdAfx.h"
#include "dh2_object.h"

dh2_object::dh2_object(void)
{
	this->itor = o_list.begin();
}

dh2_object::~dh2_object(void)
{
	if(!o_list.empty())
		for(itor=o_list.begin(); itor != o_list.end();){
			o_list.erase(itor++);
		}
}
image * dh2_object::getImage()
{
	return &this->ch_img;
}
void dh2_object::set(string in_name,int in_x, int in_y, int in_type, bool in_flag_move)
{
	this->name = in_name;
	this->set_xy(in_x, in_y);
	this->type = in_type;
	this->flag_move = in_flag_move;
}
void dh2_object::add(dh2_object * item)
{
	this->o_list.push_back(item);
}
dh2_object * dh2_object::get(string in_name)
{
	dh2_object * r_value = NULL;	
	
	if(!o_list.empty()) //비어있지 않으면
	{
		if(itor == o_list.end()) //끝이면 처음으로
			itor = o_list.begin();
		if(in_name != "none")	//같은 이름을 찾는 연산
			for(itor=o_list.begin(); itor != o_list.begin(); itor++)
				if((*itor)->name == in_name)
					break;
		r_value = *itor;
	}
	return r_value;
}
int dh2_object::getCount()
{
	return o_list.size();
}
void dh2_object::set_xy(int in_x, int in_y)
{
	this->xy.x = in_x;
	this->xy.y = in_y;
	this->ch_img.set_xy(xy.x, xy.y);

	this->xy.h = this->ch_img.offset.h;
	this->xy.w = this->ch_img.offset.w;
}

